package com.market.order.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.market.common.log.annotation.Log;
import com.market.common.log.enums.BusinessType;
import com.market.common.security.annotation.RequiresPermissions;
import com.market.order.common.domain.TOrderDetail;
import com.market.order.server.service.ITOrderDetailService;
import com.market.common.core.web.controller.BaseController;
import com.market.common.core.utils.poi.ExcelUtil;
import com.market.common.core.web.page.TableDataInfo;
import com.market.common.core.domain.Result;

/**
 * 订单明细表Controller
 *
 * @author market
 * @date 2024-02-26
 */
@RestController
@RequestMapping("/orderDetail")
public class TOrderDetailController extends BaseController
{
    @Autowired
    private ITOrderDetailService tOrderDetailService;

    /**
     * 根据orderid查询订单明细表列表
     */
    @PostMapping("/list/{orderId}")
    public Result<TableDataInfo> list(@PathVariable Integer orderId){
        startPage();
        List<TOrderDetail> list=tOrderDetailService.selectOrderDetailList(orderId);
        return getDataTable(list);
    }

    /**
     * 查询订单明细表列表
     */
    @RequiresPermissions("order:order:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(TOrderDetail tOrderDetail)
    {
        startPage();
        List<TOrderDetail> list = tOrderDetailService.selectTOrderDetailList(tOrderDetail);
        return getDataTable(list);
    }

    /**
     * 导出订单明细表列表
     */
    @RequiresPermissions("order:order:export")
    @Log(title = "订单明细表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TOrderDetail tOrderDetail)
    {
        List<TOrderDetail> list = tOrderDetailService.selectTOrderDetailList(tOrderDetail);
        ExcelUtil<TOrderDetail> util = new ExcelUtil<TOrderDetail>(TOrderDetail.class);
        util.exportExcel(response, list, "订单明细表数据");
    }

    /**
     * 获取订单明细表详细信息
     */
    @RequiresPermissions("order:order:query")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Integer id)
    {
        return success(tOrderDetailService.selectTOrderDetailById(id));
    }

    /**
     * 根据orderid获取订单明细表详细信息
     */
    @RequiresPermissions("order:order:query")
    @PostMapping(value = "/getDetailInfo/{orderId}")
    public Result<List<TOrderDetail>> getDetailInfo(@PathVariable("orderId") Integer orderId){
       List<TOrderDetail> list=tOrderDetailService.getDetailInfo(orderId);
       return Result.success(list);
    }

    /**
     * 新增订单明细表
     */

    @Log(title = "订单明细表", businessType = BusinessType.INSERT)
    @PostMapping
    public Result addDetail(@RequestBody TOrderDetail tOrderDetail)
    {
        return toAjax(tOrderDetailService.insertTOrderDetail(tOrderDetail));
    }

    /**
     * 修改订单明细表
     */
    @RequiresPermissions("order:order:edit")
    @Log(title = "订单明细表", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody TOrderDetail tOrderDetail)
    {
        return toAjax(tOrderDetailService.updateTOrderDetail(tOrderDetail));
    }

    /**
     * 删除订单明细表
     */
    @RequiresPermissions("order:order:remove")
    @Log(title = "订单明细表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public Result remove(@PathVariable Integer[] ids)
    {
        return toAjax(tOrderDetailService.deleteTOrderDetailByIds(ids));
    }
    /*
    * 根据orderid查询订单详情列表
    * */
    @PostMapping("/findDetail/{orderId}")
    public Result<List<TOrderDetail>> findDetail(@PathVariable Integer orderId){
        return tOrderDetailService.findDetail(orderId);
    }


}
